import { useRouter,useRoute } from "vue-router";
import EventBus from "~/tools/EventBus.js";

const createRouter = () => {
    let router = useRouter();
    // console.log(router);
    return {
        ...router,
        push: (param) => {
            if (!param.path) {
                console.warn("push的参数中没有path");
                return;
            };
            router.push(param);
            EventBus.emit("ROUTER-PUSH", {
                ...param
            });
            
        },
        replace: (param) => {
            if (!param.path) {
                console.warn("replace的参数中没有path");
                return;
            };
            router.replace(param);
            EventBus.emit("ROUTER-REPLACE", {
                ...param
            });
            
        },
        go:(flag)=>{
            if(flag  != -1){
                console.warn("参数只支持-1");
                return;
            };
            router.go(-1);
        },
        back:()=>{
             router.go(-1);
        },
    };
};

const createRoute = ()=>{
    const route = useRoute();
    return route;
};

export {
    createRouter,
    createRoute,
}